package com.h.chatroom.common.util;

import com.h.chatroom.pojo.dataobject.Friend;
import com.h.chatroom.pojo.dataobject.User;
import com.h.chatroom.pojo.response.FriendListResponse;
import com.h.chatroom.pojo.response.UserInfoResponse;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class BeanTransUtils {

    public static UserInfoResponse trans(User user) {
        if(user == null) {
            return null;
        }
        UserInfoResponse response = new UserInfoResponse();
        BeanUtils.copyProperties(user,response);
        return response;
    }

    public static FriendListResponse trans(Friend friend) {
        if(friend == null) return null;
        FriendListResponse response = new FriendListResponse();
        BeanUtils.copyProperties(friend,response);
        return response;
    }
    public static List<FriendListResponse> trans(List<Friend> friends) {
        if(friends == null) {
            return null;
        }
        List<FriendListResponse> response = friends.stream()
                .map(friend -> BeanTransUtils.trans(friend))
                .collect(Collectors.toList());
        return response;
    }
}
